package com.byq.mm.gateway;


import java.io.IOException;


import android.content.Context;
import android.content.Intent;


import com.tc.gateway.*;
import com.tc.gateway.tunnel.TunnelServer;


public class AndroidHomeApplication implements HomeApplication, ErrorListener{
	HomeApplication proxy;
	public AndroidHomeApplication(Context ctx) {
		super();
		this.context = ctx;
		try {
			Class type = Class.forName("com.tc.zigbee.application.ZigbeeHomeApplication");
			try {
				proxy = (HomeApplication)type.newInstance();
				proxy.setErrorListener(this);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


	}
	Context context;
	@Override
	public void onException(Throwable e) {
		stop();
		Intent intent = new Intent(AssistanceAction.ACTION_HOME_ERROR);
		context.sendBroadcast(intent);

	}

	@Override
	public GatewayEngine getGatewayEngine() {
		// TODO Auto-generated method stub
		return proxy.getGatewayEngine();
	}

	@Override
	public boolean isStarted() {
		// TODO Auto-generated method stub
		return proxy.isStarted();
	}

	@Override
	public void start() throws ProxyException, IOException {
		proxy.start();

	}

	@Override
	public void stop() {
		proxy.stop();

	}

	@Override
	public void setErrorListener(ErrorListener ls) {
		// TODO Auto-generated method stub

	}

	@Override
	public TunnelServer getTunnelServer() {
		// TODO Auto-generated method stub
		return proxy.getTunnelServer();
	}
}
